<template>
	<div class="content">
		<div class="answer_con" v-if="Question">
			<div class="timing" v-if="!isRecitation && !autoCorrecting && Paper">
				<clock ref="timer" @timerSucess="submitSure" startTime="1256322" :endTime="Paper.endtime" :timing="clockTime" :isCountdown="isCountDown" @end="timeOut"></clock>
			</div>
			<div class="question" v-if="Question[curNumber]">
				<!-- 题目 -->
				<div class="queName">
					<span class="queType">{{ queType }}</span>
					<h1 class="f20">{{ Question[curNumber].number }}、{{ Question[curNumber].queTitle }}</h1>
					<div class="queColle" :class="[Question[curNumber].collect ? 'collectBtn' : '']" v-if="isRecitation || autoCorrecting" @click="collectBtn">
						<i class="iconfont icon-shoucang_dati"></i>
						收藏
					</div>
				</div>

				<!-- 选项 -->
				<div class="queOption">
					<div class="option" :class="opClassList(index)" v-for="(item, index) in options" :key="index">
						<div @click="choseOption(index)">
							<!-- 常规按钮 -->
							<i class="normalIcon">{{ toChar(index) }}</i>
							<!-- 正确按钮 -->
							<i class="iconfont icon-_datixuanxiang iconRight" />
							<!-- 错误按钮 -->
							<i class="iconfont icon-x_datixuanxiang iconFalse" />
							{{ item }}
						</div>
					</div>
				</div>
			</div>
			<!-- 题目操作 -->
			<div class="optionOpra">
				<div class="optionNum f18">
					<span class="optionBtn" @click="changeNumer(1)">上一题</span>
					<span class="optionBtn" @click="changeNumer(2)">下一题</span>
					<span class="optionSubmit" v-if="!isRecitation && !autoCorrecting" @click="submitPaper">
						<i class="iconfont icon-jiaojuan"></i>
						交卷
					</span>
				</div>
				<div class="optionCheck f18">
					<span v-if="isRecitation || autoCorrecting" :class="[isAnalysisSta ? 'bgGreen' : '']" @click="isShowFuc">查看解析</span>
					<span @click="ScantronFlase = !ScantronFlase">答题卡</span>
				</div>
			</div>

			<!-- 设置跳转 -->
			<div class="queSet f16">
				<el-checkbox v-model="jumpCheck" v-if="!isRecitation && autoCorrecting" style="margin-right: 50px;"><span class="f16">答对自动跳转下一题</span></el-checkbox>
				<div class="queSetPro">
					当前进度:{{ Question[curNumber].number }}
					<span>/{{ Question.length }}</span>
				</div>

				<div class="queSetNum" v-if="isShowAnalysis && !isRecitation">
					<div class="OptionLi right">
						<i class="iconfont icon-_datixuanxiang iconRight" />
						{{ CorrectCountFuc }}
					</div>
					<div class="OptionLi false">
						<i class="iconfont icon-x_datixuanxiang iconFalse"></i>
						{{ ErrorCountFuc }}
					</div>
				</div>
			</div>
			<!-- 你的答案 -->
			<div class="queAnswer" v-if="isShowAnalysis && !Formalexam">
				<div>
					<h3 class="f18">你的答案：</h3>
					<span class="f22 org">{{ Question[curNumber].userChoice || '未答' }}</span>
				</div>
				<div>
					<h3 class="f18">正确答案：</h3>
					<span class="f22 gre">{{ Question[curNumber].rightAnswer }}</span>
				</div>
			</div>
			<!-- 题目解析 -->
			<div class="queAnaliy" v-if="isShowAnalysis">
				<div class="detailTit">
					题目解析
					<div class="grayBor" @click="dialogVisible = true">纠错</div>
				</div>
				<div class="queAnaliyTxt f16">{{ Question[curNumber].queAnalysis }}</div>
			</div>
			<!-- 答题卡 -->
			<Scantron
				v-if="ScantronFlase"
				:topicList="Question"
				:topicNumber="curNumber + 1"
				:CountVO="CountVO"
				:topicType="topicType"
				@jumpNum="jumpNum"
				:isCorrecting="isCorrecting"
			></Scantron>
			<div class="queWarn" v-if="ScantronFlase && !isRecitation && autoCorrecting">
				<div class="queWarnNode f16">温馨提示：点击清除当前做题记录，记录会被清空，可重新答题喔~</div>
				<div class="queWarnBtn" @click="updateAnswerHistory">清除记录</div>
			</div>
		</div>
		<Popup v-if="subModalShow" :mold="1" :btnTxt="['现在提交', '继续做题']" @closeClick="closeModal" @cancelClick="submitSure" @configClick="closeModal">
			<div slot="modalSlot">
				<template v-if="incomplete > 0">
					当前还有
					<span>{{ incomplete }}</span>
					题未做
				</template>
				<template v-else>
					确定现在交卷吗？
				</template>
			</div>
		</Popup>
		<Popup v-if="clearModalShow" :mold="1" :btnTxt="['取消', '确定']" @closeClick="clearModalShow = false" @cancelClick="clearModalShow = false" @configClick="clearSubmit">
			<div slot="modalSlot">你确定要清除答题记录吗</div>
		</Popup>
		<Popup v-if="subModalShow2" :mold="2" :title="warnTitile"></Popup>
		<Popup v-if="subModalShow3" :mold="3" title="提交成功"></Popup>
		<errorRecovery :dialogVisible="dialogVisible" @cancel="dialogVisible = false" @submit="recoverySubmit"></errorRecovery>
	</div>
</template>

<script>
export default {
	name: 'Answer',
	props: {
		CountVO: {
			//题卡
			type: Object,
			required: true
		},
		Question: {
			//题目
			type: Array,
			required: true
		},
		Paper: {
			//试卷信息
			type: Object,
			required: true
		},
		CorrectCount: {
			//正确数量
			type: Number,
			required: true
		},
		ErrorCount: {
			//错误数量
			type: Number,
			required: true
		},
		isRecitation: {
			//背题模式
			type: Boolean
		},
		isCorrecting: {
			//是否批改
			type: Boolean
		},
		autoCorrecting: {
			//是否自动批改  我的错题模式
			type: Boolean
		},
		isCountDown: {
			//是否倒计时
			type: Boolean,
			default: true
		},
		updateHis: {
			//更新历史记录
			type: String
		},
		topicNumber: {
			//起始题号
			type: Number
		},
		Formalexam: {
			//是否正式开卷
			type: Boolean,
			default: false
		},
		leaveStatus: {
			//是否离开 更新答题
			type: Boolean,
			default: false
		},
		clearType: {
			// 收藏进入
			type: Boolean,
			default: false
		},
		clearWrong: {
			//错题页是否已经更新过
			type: Boolean,
			default: false
		},
		isClock: {
			//每日一练进入
			type: Number
		}
	},
	data() {
		return {
			curNumber: 0, //当前题目索引
			userChoice: [], //多选的答案存放
			isFinished: false, //是否完成
			topic: {}, //当前
			topicType: [], //题卡
			groupCount: 100, //每组数量
			timing: '', //计时
			ScantronFlase: false, //答题卡显示
			isShowAnalysis: false, //题目解析
			isAnalysisSta: false, //解析样式状态
			subModalShow: false, //提交弹窗、
			subModalShow2: false, //交卷提示
			subModalShow3: false, //提交意见成功
			clearModalShow: false, //清除弹窗
			incomplete: 0, //未做题目
			isjump: true, //是否可以下一题
			dialogVisible: false, //纠错弹窗
			jumpCheck: false, //答对自动跳转
			Multiple: false, //是否是多选
			lastToptic: {}, //刚被切换的数据
			warnTitile: '正在交卷中...', //弹框提示
			subBtnSta: false, //交卷按钮状态
			subBtnClickSta: false, //是否点击了交卷按钮
			subBtnChecK: false, //交卷检查
			answerHistoryList: [], //已答题目存放
			setTimerDestroy: 0, //卸载前的时间
			isSetClock: this.isClock ? this.isClock : 0 //是否每日一练进入
		};
	},
	watch: {
		ScantronFlase() {
			this.topicTypeFuc();
		},
		curNumber() {
			if (!this.isRecitation && this.Formalexam) {
				//如果是答题模式 每一题都可随意更改答案
				this.Question[this.curNumber].isFinished = false;
			} else if (!this.isRecitation && !this.Formalexam && this.Question[this.curNumber].isFinished) {
				//答题模式不是正式考试 用户已经选择了答案
				this.isShowAnalysis = true;
			}
		}
	},
	beforeDestroy() {
		this.setTimerDestroy = this.getUsedTime();
	},
	destroyed() {
		if (this.updateHis && !this.subBtnSta) {
			this.updateHistoryHander(this.updateHis, this.Question[this.curNumber]); //更新答题记录
		}
		if (this.updateHis === 'updateExamHistory' && !this.subBtnSta && this.Formalexam) {
			//提交试卷接口
			const { queId = null, number = null } = this.Question[this.curNumber];
			const { upid = null } = this.CountVO; //获取试卷的信息
			const pageData = {
				answerHistoryList: this.answerHistoryList, //提交的题目
				duration: this.setTimerDestroy,
				number,
				queId,
				upid
			};
			if (!this.subBtnClickSta) {
				// 如果没有点击交卷
				this.axios.post(`/web/student/exam/outExam`, pageData).then(() => {});
			}
		}
	},
	created() {
		this.answerHistoryList = [];
		this.topicTypeFuc(); //题卡信息
		this.curNumber = this.topicNumber ? this.topicNumber - 1 : 0;
		// this.isFinished = this.isRecitation;
		if ((this.isRecitation && this.isCorrecting) || (!this.isRecitation && this.autoCorrecting)) {
			//全真模拟错题和回顾试卷  //我的错题用户已经选择了答案
			this.isFinished = true;
			this.Question[this.curNumber].isFinished = true;
			if (this.isRecitation && !this.Formalexam) {
				//错题应自动显示解析
				this.isShowAnalysis = true;
			}
			if (!this.isRecitation && this.isCorrecting) {
				if (this.Question[this.curNumber].userChoice) return; //答题模式已经有答案了
				//在线练习背题模式
				this.Question[this.curNumber].isFinished = false;
			}
		}
	},
	computed: {
		options() {
			//提取选项
			const topic = this.Question[this.curNumber];
			if (this.Question[this.curNumber].qusTypeId === 3) {
				return ['正确', '错误'];
			}
			return Object.keys(topic)
				.filter(key => key.includes('queOption'))
				.reduce((opList, opKey) => {
					if (topic[opKey] && topic[opKey] !== '') opList.push(topic[opKey]);
					return opList;
				}, []);
		},
		isSingleTopic() {
			//是否正确
			return /1|3/.test(this.Question[this.curNumber].qusTypeId);
		},
		formatUserChoice() {
			return this.userChoice.join('');
		},
		totalTopicCount() {
			//总提数
			return this.Question.length;
		},
		answeredCount() {
			//答题数量
			return this.Question.filter(topic => topic.userChoice).length;
		},
		ErrorCountFuc() {
			return this.Question.filter(topic => !topic.isCorrect && topic.userChoice).length;
		},
		CorrectCountFuc() {
			return this.Question.filter(topic => topic.isCorrect).length;
		},
		queType() {
			return this.Question[this.curNumber].qusTypeId == 1 ? '单选' : this.Question[this.curNumber].qusTypeId == 2 ? '多选' : '判断';
		},
		clockTime() {
			if (!this.isCountDown) {
				return this.Paper.duration ? this.Paper.duration : 0;
			} else {
				return this.Paper.minutes - this.Paper.duration;
			}
		}
	},
	methods: {
		//题卡计算
		topicTypeFuc() {
			//背题模式
			if (this.isRecitation) {
				this.userChoice = [];
			}
			//正常做题
			if (this.Question[this.curNumber].userChoice) {
				this.userChoice = this.Question[this.curNumber].userChoice.split('');
			} else {
				this.userChoice = [];
			}
			// if (this.isCorrecting) this.isFinished = this.manualViewAnalysis = n.isCorrect !== null || false;
			this.topicType = [];
			//题卡
			['单选题', '多选题', '判断题'].map((name, index) => {
				// type 0单选题  1 多选题  2判断题
				this.topicType.push({ name, count: 0, startIndex: 0, group: null, score: null, type: index });
			});

			//题目数量 /分值;
			this.topicType[0].count = this.CountVO.singleChoiceCount;
			this.topicType[0].score = this.CountVO.singleChoiceScore;
			this.topicType[1].count = this.CountVO.multipleChoiceCount;
			this.topicType[1].score = this.CountVO.multipleChoiceScore;
			this.topicType[2].count = this.CountVO.trueFalseCount;
			this.topicType[2].score = this.CountVO.trueFalseScore;
			//题目开始下标
			this.topicType[1].startIndex = this.CountVO.singleChoiceCount;
			this.topicType[2].startIndex = this.CountVO.singleChoiceCount + this.CountVO.multipleChoiceCount;
			// 	//题号分组
			this.topicType[0].group = this.groupTopicNumber(this.CountVO.singleChoiceCount, 0, this.groupCount);
			this.topicType[1].group = this.groupTopicNumber(this.CountVO.multipleChoiceCount, this.topicType[1].startIndex, this.groupCount);
			this.topicType[2].group = this.groupTopicNumber(this.CountVO.trueFalseCount, this.topicType[2].startIndex, this.groupCount);
		},
		isShowFuc() {
			// 查看解析
			this.isShowAnalysis = !this.isShowAnalysis;
			if (this.Question[this.curNumber].qusTypeId == 2) {
				//如果多选题查看解析  判断为已完成
				this.isFinished = true;
				this.Multiple = false;
				this.userChoice = [];
				this.Question[this.curNumber].isFinished = true; //多选题完成后再判断结束
				if (this.curNumber != this.Question.length - 1 && this.jumpCheck) {
					//如果不是最后一题 已经答对 而且已选择自动跳转
					if (this.Question[this.curNumber].rightAnswer != this.Question[this.curNumber].userChoice) return;
					this.curNumber++;
					this.isShowAnalysis = false;
				}
			} else {
				this.Question[this.curNumber].isFinished = true; //单选题自动判断已结束
			}
		},
		changeNumer(type) {
			if ((this.Multiple && this.curNumber != this.Question.length - 1) || this.Question[this.curNumber].qusTypeId == 2) {
				// 如果是多选题切换 // 并且不是最后一题
				this.isFinished = true;
				this.Multiple = false;
				this.userChoice = [];
			}
			this.isAnalysisSta = false; //查看解析状态
			this.lastToptic = this.Question[this.curNumber]; //存住当前提
			if (type == 1) {
				//上一题
				if (this.curNumber != 0) {
					// 如果不是第一题
					this.curNumber--;
				}
			} else {
				// 下一题
				if (this.curNumber == this.Question.length - 1) return;
				//如果不是最后一题
				this.curNumber++;
			}
			this.Question[this.curNumber].isFinished = true;
			// this.isShowAnalysis=true;
			if (this.isRecitation && !this.Formalexam) {
				//错题应自动显示解析
				this.isShowAnalysis = true;
			}
			//我的错题如果用户已经有选项了 则自动判断
			if (!this.Question[this.curNumber].userChoice) {
				if (!this.isRecitation && this.autoCorrecting) {
					this.isFinished = false;
					this.Question[this.curNumber].isFinished = false;
				}
			}
			if (this.updateHis && this.curNumber != 0) {
				//不是第一题
				this.updateHistoryHander(this.updateHis, this.lastToptic); //更新答题记录
			}
		},
		submitPaper() {
			// 点击交卷
			this.subBtnChecK = true;
			if (this.updateHis) {
				this.updateHistoryHander(this.updateHis, this.Question[this.curNumber]); //更新答题记录
			}
		},
		updateHistoryHander(hander, data) {
			data = data ? data : this.Question[this.curNumber];
			const isCorrect = data.rightAnswer === data.userChoice;
			data.isCorrect = isCorrect;
			if (!data.userChoice) {
				data.isCorrect = null;
			}
			if (!this.isRecitation && this.isCorrecting && this.autoCorrecting) {
				// 我的错题模式可以跳转下一题
				this.isjump = true;
			}
			// if (this.isRecitation && !this.autoCorrecting && !this.autoCorrecting) return; //非答题模式
			if (!this.isjump) return; // 如果题目未成功更新
			this.isjump = false;
			if (this.isRecitation && !this.Formalexam) {
				//错题应自动显示解析
				this.isShowAnalysis = true;
			} else {
				this.isShowAnalysis = false; //跳转后默认隐藏解析
			}
			return this[hander](data);
		},
		updateExamHistory(topic) {
			// 考试更新答题记录
			const { userChoice, rightAnswer, number } = topic;
			if (!this.Formalexam && this.isRecitation) return;

			topic.duration = this.getUsedTime();
			topic.isCorrect = rightAnswer === userChoice;
			this.userChoice = []; //清空多选
			// const pageData = {
			// 	duration: duration, //耗时
			// 	historyId: historyId,
			// 	isCorrect: isCorrect, //是否正确
			// 	number: number,
			// 	userChoice: userChoice
			// };
			this.Question[number - 1].userChoice = userChoice;
			this.isjump = true; //是否可更换下一题
			if (this.Formalexam && !this.isRecitation) {
				//正式答题进入 并且不是背题模式
				this.Question[this.curNumber].isFinished = false;
			}
			if (userChoice) {
				this.answerHistoryList.push(topic);
			}
			if (this.subBtnChecK) {
				//答题提交之前验证
				let checkItem = [];
				this.Question.filter(item => {
					if (!item.userChoice) {
						checkItem.push(item.historyId);
					}
				});
				setTimeout(() => {
					this.subModalShow = true; //弹窗提示
					this.subBtnChecK = false;
					this.incomplete = checkItem.length; //有多少未做的题
				}, 200);
			}
			if (this.subBtnSta) {
				//如果点击交卷状态
				this.submitPost();
			}
			// ///更新答题记录
			// this.axios.post('/web/student/exam/updateAnswerHistory', pageData).then(res => {

			// 	this.isjump = true; //是否可更换下一题
			// 	if (this.Formalexam && !this.isRecitation) {
			// 		//正式答题进入 并且不是背题模式
			// 		this.Question[this.curNumber].isFinished = false;
			// 		if (this.subBtnChecK) {
			// 			//答题提交之前验证
			// 			const { upid = null } = this.CountVO; //获取试卷的信息
			// 			this.axios.get(`/web/student/exam/getUnanswered/${upid}`).then(res => {
			// 				this.subModalShow = true; //弹窗提示
			// 				this.subBtnChecK = false;
			// 				this.incomplete = res.length; //有多少未做的题
			// 				this.notDone(res); //清除题目
			// 			});
			// 		}
			// 		// if (this.subBtnSta) {
			// 		// 	//如果点击交卷状态
			// 		// 	this.submitPost();
			// 		// }
			// 	}
			// 	if(res.code!=0){
			// 		this.curNumber=number-1
			// 		this.Question[number-1].isFinished=false
			// 		this.Question[number-1].userChoice=null
			// 	}
			// 	console.log(res, '成功更新答题');
			// });
		},
		updateExercise(topic) {
			// let {number}=this.lastToptic
			const pageData = {
				type: 1,
				number: topic.number,
				queid: topic.queId,
				chapterid: topic.chapterId,
				examid: topic.examId,
				paperid: topic.paperId
			};
			//章节练习背题模式更新
			this.axios.post('/web/student/exercise/reciteQuestion', pageData).then(res => {
				this.isjump = true; //是否可更换下一题
				console.log(res, '背题模式更新返回');
			});
		},
		updateExerciseAnswer(topic) {
			const pageData = topic;
			//章节练习答题模式更新
			this.axios.post('/web/student/exercise/addAnswerHistory', pageData).then(res => {
				this.isjump = true; //是否可更换下一题
				console.log(res, '答题模式更新返回');
			});
		},
		updateErrorAnswer(topic) {
			let { colqueid, userChoice, isCorrect, number, collect } = topic;
			if (!userChoice || this.clearWrong) return;
			const pageData = {
				colqueid,
				userChoice,
				isCorrect,
				number: number
			};
			if (collect==null && this.clearType) return;
			this.axios.post('/web/student/collect/collectAnswer', pageData).then(res => {
				this.isjump = true; //是否可更换下一题
				console.log(res, '我的错题更新返回');
			});
		},
		timerSeconds() {
			//获取定时器剩余时间
			if (this.$refs.timer) {
				return this.$refs.timer.setTiming;
			}
		},
		getUsedTime() {
			//获取用户耗时
			//正计时直接获取timer 时间
			if (!this.isCountDown) return this.timerSeconds();
			//倒计时计算耗时
			return this.Paper.minutes - this.timerSeconds();
		},
		toChar(num) {
			//数字转字母
			return String.fromCharCode(65 + num);
		},
		jumpNum(e) {
			if (this.Multiple || this.Question[this.curNumber].qusTypeId == 2) {
				// 如果是多选题切换
				this.isFinished = true;
				this.Multiple = false;
				this.userChoice = [];
			}
			this.isAnalysisSta = false; //查看解析状态
			this.lastToptic = this.Question[this.curNumber];
			this.curNumber = e - 1;
			if (this.isRecitation && !this.Formalexam) {
				//错题应自动显示解析
				this.isShowAnalysis = true;
			}
			//答题卡跳转
			if (this.updateHis) {
				this.updateHistoryHander(this.updateHis, this.lastToptic);
			}
			this.Question[this.curNumber].isFinished = true;
			//我的错题如果用户已经有选项了 则自动判断
			if (!this.Question[this.curNumber].userChoice) {
				if (!this.isRecitation && this.autoCorrecting) {
					this.isFinished = false;
					this.Question[this.curNumber].isFinished = false;
				}
			}
		},
		timeOut() {
			//时间结束
			this.subBtnClickSta = true;
			this.submitSure(); //时间结束即交卷
		},
		submitSure() {
			this.subModalShow = false;
			this.warnTitile = '正在交卷中...';
			this.subModalShow2 = true;
			if (this.updateHis) {
				//如果时间结束更新答题记录
				this.updateHistoryHander(this.updateHis, this.Question[this.curNumber]); //更新答题记录
			}
			this.submitPost();
			// this.subBtnSta = true;
		},
		closeModal() {
			this.subBtnSta = false;
			this.subBtnClickSta = false;
			this.subModalShow = false;
		},
		submitPost() {
			//提交试卷接口
			const duration = this.getUsedTime();
			const { paperId = null, examId = null, queId = null, number = null } = this.Question[this.curNumber];
			const { upid = null, ueid = null } = this.CountVO; //获取试卷的信息
			const pageDataSet = {
				answerHistoryList: this.answerHistoryList, //提交的题目
				duration,
				number,
				queId,
				upid
			};
			this.axios.post(`/web/student/exam/outExam`, pageDataSet).then(() => {
				this.subBtnClickSta = true;
				const pageData = {
					examid: examId,
					paperid: paperId,
					duration,
					ueid,
					upid,
					isClock: this.isSetClock
				};
				this.axios
					.post('/web/student/exam/submitPaper', pageData)
					.then(() => {
						// 交卷成功
						this.subModalShow2 = false;
						this.$emit('sumitSucess', upid);
					})
					.catch(() => {
						this.submitPost();
					});
			});
		},
		configClick() {
			//确定
			this.subModalShow = false;
		},
		choseOption(index) {
			const optionCh = this.toChar(index);
			let ques = this.Question[this.curNumber];
			if (this.Question[this.curNumber].isFinished) return;
			// if (this.isFinished) return; //如果答题已结束
			//单选/判断 this.Question[this.curNumber].qusTypeId==2是多选
			if (ques.qusTypeId != 2) {
				//单选或者判断
				this.$set(this.Question[this.curNumber], 'userChoice', optionCh);
				this.Question[this.curNumber].isCorrect = this.isRightAnswer(index);
				this.Question[this.curNumber].isFinished = true;
				this.isFinished = true;
				this.Multiple = false;
				if (this.isRightAnswer(index) && this.jumpCheck && this.curNumber + 1 != this.Question.length) {
					//如果选择正确自动跳转
					this.curNumber++;
					this.isShowAnalysis = false;
					this.Question[this.curNumber].isFinished = false;
				}
			} else {
				let opIndex = 0;
				this.Multiple = true;
				if (this.userChoice) {
					opIndex = this.userChoice.indexOf(optionCh);
					if (!this.isRecitation && this.autoCorrecting) {
						this.isAnalysisSta = true;
					}
				}
				// 多选
				if (opIndex === -1) {
					this.userChoice.push(optionCh);
				} else {
					this.userChoice.splice(opIndex, 1);
				}
				this.userChoice = this.userChoice.sort();
				this.Question[this.curNumber].userChoice = this.formatUserChoice;
			}
			if (this.autoCorrecting && this.Question[this.curNumber].userChoice) {
				//单选题自动展示解析  是否答题判断：答题模式如果自动跳转阻止展示
				this.isShowAnalysis = this.Question[this.curNumber].qusTypeId != 2 ? true : false;
			}
		},
		isRightAnswer(index) {
			const optionCh = this.toChar(index);
			const { rightAnswer } = this.Question[this.curNumber];
			// console.log(rightAnswer,optionCh,'正确答案')
			//正确答案
			if (rightAnswer.includes(optionCh)) return true;
			//用户选择错误答案
			if (this.isUserChecked(index)) return false;
		},
		isUserChecked(index) {
			const optionCh = this.toChar(index);
			return this.Question[this.curNumber].userChoice ? this.Question[this.curNumber].userChoice.includes(optionCh) : false;
		},
		isNormalOption(index) {
			//用户未选择并且不是正确答案的选项
			return !this.isUserChecked(index) && !this.isRightAnswer(index);
		},
		opClassList(index) {
			const classList = ['option'];
			const option = this.toChar(index);

			if (!this.Question[this.curNumber].userChoice && !this.isRecitation && !this.isCorrecting) return; //如果没有选择 不操作
			//checked条件：题目未完成&&不批改题目&&不是背题模式&& //我的错偷模式多选进入
			if ((!this.isCorrecting && !this.isRecitation) || (this.Multiple && this.autoCorrecting)) {
				if (!this.Question[this.curNumber].userChoice) return;
				this.Question[this.curNumber].userChoice.includes(option) && classList.push('checked');
			} else if (this.Question[this.curNumber].isFinished && !this.isNormalOption(index)) {
				classList.push(this.isRightAnswer(index) ? 'right' : 'wrong');
			}
			// else if (!this.isFinished && !this.isNormalOption(index) && !this.isRecitation && this.autoCorrecting) {
			// 	// 章节练习答题模式继续上次练习进入
			// 	console.log(1212)
			// 	classList.push(this.isRightAnswer(index) ? 'right' : 'wrong');
			// }
			if (!this.isRecitation && !this.isCorrecting && !this.autoCorrecting) {
				//背题模式不允许点击
				this.isFinished = false;
				this.Question[this.curNumber].isFinished = false;
			}
			return classList;
		},
		groupTopicNumber(count, baseNumber, groupSize = 100) {
			//对题号进行分组
			const group = [];
			const fullGroup = count / groupSize;
			for (let i = 1; i < fullGroup + 1; i++) {
				const start = (i - 1) * groupSize + 1;
				let end;
				if (fullGroup < i && count % groupSize) end = count;
				else end = i * groupSize;
				end && group.push({ start: start + baseNumber, end: end + baseNumber });
			}
			return group;
		},
		updateAnswerHistory() {
			//清除答题记录
			this.isShowAnalysis = false;
			this.clearModalShow = true;
		},
		notDone(data) {
			//未做题清除
			for (let i of data) {
				this.Question.forEach(item => {
					if (item.historyId == i) {
						item.userChoice = '';
					}
				});
			}
		},
		clearSubmit() {
			this.curNumber = 0;
			let curData = this.Question[this.curNumber];
			let params = {
				chapterId: curData.chapterId,
				paperId: curData.paperId,
				examid: curData.examId,
				type: this.clearType ? 1 : 2
			};
			this.warnTitile = '正在清除答题记录...';
			this.subModalShow2 = true;
			this.isShowAnalysis=false;
			//在线练习清除答题记录 updateExercise 背题模式   updateExerciseAnswer 答题模式
			if (this.updateHis == 'updateExercise' || this.updateHis == 'updateExerciseAnswer') {
				let type = this.updateHis == 'updateExercise' ? 1 : 2;
				let chapterId = this.Question[this.curNumber].chapterId;
				// 清除答题记录
				this.axios.delete(`/web/student/exercise/deleteSchedule/${chapterId}/${type}`).then(res => {
					console.log(res, '清除成功');
					this.Paper.number = 1;
					this.isShowAnalysis=false;
					this.$emit('updateAnswerHistory', chapterId);
					this.isjump = true; //是否可更换下一题
					this.clearModalShow = false;
					this.subModalShow2 = false;
				});
				return;
			}
			// 清除答题记录
			this.axios.get('/web/student/errorQuestion/updateAnswerHistory', { params }).then(res => {
				console.log(res, '清除成功');
				let transmitData = {
					chapterId: params.chapterId,
					paperid: params.paperId,
					examid: params.examId,
					type: this.clearType ? 1 : 2
				};
				this.Paper.number = 1;
				this.$emit('updateAnswerHistory', transmitData);
				this.isjump = true; //是否可更换下一题
				this.isShowAnalysis=false;
				this.clearModalShow = false;
				this.subModalShow2 = false;
			});
		},
		collectBtn() {
			//收藏
			let { chapterId, queId, collect, examId, paperId } = this.Question[this.curNumber];
			let collectData = {
				chapterId,
				queId,
				collect,
				examId,
				paperId
			};
			// 收藏
			this.axios.post('/web/student/collect/addAndDeleteCollect', collectData).then(res => {
				this.Question[this.curNumber].collect = res;
			});
		},
		recoverySubmit(data) {
			data.queId = this.Question[this.curNumber].queId;
			let that = this;
			// 纠错
			this.axios.post('/web/student/exercise/addError', data).then(function() {
				that.subModalShow3 = true;
				setTimeout(function() {
					that.subModalShow3 = false;
				}, 1000);
				that.dialogVisible = false;
			});
		}
	}
};
</script>
<style scoped>
/deep/.el-checkbox__label {
	font-size: 16px;
}
</style>
